﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using Bestlife.ERP.DataAccess;

/// <summary>
/// Summary description for _5_Agent
/// </summary>
/// 
namespace Bestlife.ERP.BusinessRules
{
public class _5_Agent
{
    string Rank;
     Boolean upd = false;
            int Num_agents = 0;
            int Num_diamond=0;
            int Num_Ruby = 0;
            int Num_SED = 0;
            int Num_SD = 0;

	public _5_Agent()
	{
		//
		// TODO: Add constructor logic here
		//
	}


    public Boolean five_to_5_Agent(String ID,Double cpv,Double ppv,string level)
    {
        Boolean fivetoagent = false;

            #region Starter kit

            if (ppv < 25) // 5% presenter
            {

                //Bestlife.ERP.BusinessRules._5presnter();


            }


            // }   // 5% presenter   

            #endregion  

            #region 5% presenter

            if (cpv>=50 && cpv<100) // 5% presenter
                
            {                       
                
                                    //

                                    try
                                    {
                                        String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                                        Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                                        //String updStatus = "UPDATE Bonus  SET user_Status='2',bv='" + 0.0 + "',ppv='"+0.0+"' WHERE User_id='" + ID + "'";
                                        String updStatus = "UPDATE Bonus  SET user_Status='2'WHERE User_id='" + ID + "'";
                                        upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
                                        fivetoagent = upd;
                                        Rank = "2";
                                    }


                                    catch 
                                    {

                                    }


                                    finally
                                    {
                                        clsCon.conn_new.Close();
                    
                                    }


           }

           // }   // 5% presenter   

        #endregion  

            #region 10% presenter

            else if (cpv>=100 && cpv<200) 
            {

            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                //String updStatus = "UPDATE Bonus  SET user_Status='3',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + ID + "'";
                String updStatus = "UPDATE Bonus  SET user_Status='3' WHERE User_id='" + ID + "'";
                upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
                fivetoagent = upd;
                Rank = "3";
            }


            catch
            {

            }


            finally
            {
                clsCon.conn_new.Close();

            }


            }

            #endregion  

            #region 15% presenter


            else if (cpv >= 200 && cpv < 300)
            {

                try
                {
                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                    //String updStatus = "UPDATE Bonus  SET user_Status='4',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + ID + "'";
                    String updStatus = "UPDATE Bonus  SET user_Status='4' WHERE User_id='" + ID + "'";
                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
                    fivetoagent = upd;
                    Rank = "4";
                }


                catch
                {

                }


                finally
                {
                    clsCon.conn_new.Close();

                }
            }


            // }   // 15% presenter   

            #endregion  
 
            #region Agent


            else if (cpv >= 300 && cpv <1500)
            {

                try
                {
                    String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                    Bestlife.ERP.DataAccess.clsCon.connect(connStr);
                    //String updStatus = "UPDATE Bonus  SET user_Status='5',bv='" + 0.0 + "',ppv='" + 0.0 + "' WHERE User_id='" + ID + "'";
                    String updStatus = "UPDATE Bonus  SET user_Status='5' WHERE User_id='" + ID + "'";
                    upd = Bestlife.ERP.DataAccess.clsCon.AddEditDel(updStatus);
                    Rank = "5";
                    fivetoagent = upd;
                    String Agent = "INSERT INTO Agent (User_id,level_id,Agent_status)VALUES('" + ID + "','" + level + "','" + Rank + "')";
                    Boolean chk = Bestlife.ERP.DataAccess.clsCon.AddEditDel(Agent);
                    fivetoagent = chk;
                }


                catch
                {

                }


                finally
                {
                    clsCon.conn_new.Close();

                }


            }
           

            #endregion       
            return fivetoagent;





   }

 }//namespace

}